
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>New project</title>
	
	<link rel="stylesheet" type="text/css" href="../../themes/general.css">
	<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../../themes/gray/easyui.css">

	<script type="text/javascript" src="../../scripts/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="../../scripts/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../scripts/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../../scripts/src/jquery.parser.js"></script>
	<script type="text/javascript" src="../../scripts/general.js"></script>
	<script type="text/javascript" src="../../scripts/sessionExpriation.js"></script>

	<style type="text/css">
		.peopleChange:hover{background-color: #999;}
	</style> 
	<script type="text/javascript">
 	$(function() {
		//项目的id作为隐藏值保存在表单中
		var projectId = $.getUrlParam('projectId');
		$("#projectId").val(projectId);
		$.ajax({//获取项目名称
			url : '../../project/getProjectName.ajax',
			type : 'post',
			dataType : 'text',
			cache: false,
			data : {
				projectId : projectId,
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {	                    
	        },
			success : function(data) {	
				$('#projectName').text(decodeURI(data));
			}
		}); 
		
		//如果不是第一次填写，则需要填上其他信息
		$.ajax({//项目总监和项目经理的ajax
			url : '../../plan/getChiefAndManager.ajax',
			type : 'post',
			dataType : 'JSON',
			cache: false,
			data : {
				proId : projectId,
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {	                    
	        },
			success : function(data) {			
				//如果不是第一次填写的话，需要将以前填写过的信息显示在里面
				init_data(data);
			}
		});
		
		
		$.ajax({//文件部分
			url : '../../plan/getPlanFileInfo.ajax',
			type : 'post',
			dataType : 'JSON',
			cache: false,
			data : {
				proId : projectId 
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
	                   
	        },
			success : function(data) {
				//如果不是第一次填写的话，需要将以前填写过的信息显示在里面
				init_file(data);
			}
		});
		
		$.ajax({//人员派遣--判断按钮是否可用
			url : '../../ana/checkPermission.ajax',
			type : 'post',
			dataType : 'JSON',
			data : {
				//msgId : projectId
				permissionCode :'People_OutChoose'
			},
			success : function(data) {
				 if (data.success) {
					$('#tipProjectPeople1').show();
					$('#tipProjectPeople2').show();
				} else {
					$('#tipProjectPeople1').hide();
					$('#tipProjectPeople2').hide();
				} 
			} 
		});
		
		$.ajax({//需要数据库的人员信息
			url : '../../plan/selectByStationStatus.ajax',
			type : 'post',
			dataType : 'JSON',
		/* 	data : {
				projectId : projectId 
			}, */
			cache: false,
			error: function(XMLHttpRequest, textStatus, errorThrown) {
	                    alert(XMLHttpRequest.status);
	        },
			success : function(peopleData) {
				
				addpeople(peopleData);
			}
		});
		//人员信息的提交按钮
		 $('#new_form_people').form({
			url : '../../plan/submitPlanPeople.ajax?projectId='+projectId,
			onSubmit : function() {						
				if ($(this).form('validate')) {
					return true;//验证是否为空
				} else {
					return false;
				}
			},
			success : function(data) {
				var obj = $.parseJSON(data);//将json字符串转换为object对象
				if (obj.success) {
					$.messager.alert('提示', obj.message, 'info', function(){
						location.reload();//强迫浏览器刷新当前页面
					});
				} else {
					$.messager.alert('提示', obj.message, 'info');
				}
			}
		});
		//表单提交的ajax
		 $('#new_form_file').form({
			url : '../../plan/submitPlanFile.ajax',
			onSubmit : function() {						
				recordFileName();
				if ($(this).form('validate')) {
					return true;//验证是否为空
				} else {
					return false;
				}
			},
			success : function(data) {
				var obj = $.parseJSON(data);//将json字符串转换为object对象
				if (obj.success) {
					$.messager.alert('提示', obj.message, 'info', function(){
						location.reload();//强迫浏览器刷新当前页面
					});
				} else {
					$.messager.alert('提示', obj.message, 'info');
				}
			}
		});
		
		//事件绑定，点击提交就提交表单
		$('#btn_submit1').bind('click', function() {
			$("#new_form_people").submit();
		}); 
		$('#btn_submit').bind('click', function() {
			$("#new_form_file").submit();
		}); 

	//对话框的设置
	$( "#dialog" ).dialog({
		title: '人员派遣',
        closed:true,
        modal:true,  
     	autoOpen: true,
      
    });
    var that;

    $("#tipProjectPeople1").click(function(){
    	that = $(this).prev().prev();
    	choose_people();
    });

    $("#tipProjectPeople2").click(function(){
    	that = $(this).prev().prev();
    	choose_people();
    });
    //这个是将人员信息形成表
    function addpeople(peopleData){
		if(peopleData != null && peopleData.length > 0){
			for(var i = 0; i < peopleData.length; i++){
				$str='';
		        $str+='<tr class="peopleChange">';
		        $str+='<td align="center" width="50" class="id">' + peopleData[i].people.peoId  + '</td>';
				$str+='<td align="center" width="70" class="name">' + peopleData[i].people.peoName  + '</td>';
				$str+='<td align="center" width="100">' + peopleData[i].people.peoStationDesc  + '</td>';
				if(peopleData[i].project == null || peopleData[i].project.projectName == null)
					projectName = "";
				else
					projectName = peopleData[i].project.projectName;
			    $str+='<td align="center" width="150">' + projectName  + '</td>';
			    if(peopleData[i].people.peoContel == null)
			    	peopleData[i].people.peoContel = "";
				$str+='<td align="center" width="100">' + peopleData[i].people.peoContel  + '</td>';
				if(peopleData[i].people.peoEvectionDesc == null)
					peopleData[i].people.peoEvectionDesc = "";
				$str+='<td align="center" width="100">' + peopleData[i].people.peoEvectionDesc + '</td>';
			    $str+='</tr>';
			    $("#newPeople").append($str);
			}
		}
		$(".peopleChange").click(function(){
			var name = $(this).children('td.name').text();
			var id = $(this).children('td.id').text();
			$(that).val(name);
			$(that).next().val(id);
			$("#dialog").dialog('close');
		})
	}

});	


	//从数据库选人
	function choose_people(){
		$("#dialog").dialog('open');
	}

	//表单提交时验证 最后上传的那部分
	function recordFileName(){
		var fileNames = document.getElementsByName("fileName");//取得标签名为filename的标签对象
		var fileNameIndex 	= '';
		var fileNameVal 	= '';
		for(var k = 0; k < fileNames.length; k++){			
			var tempFileNameObject 	= 	fileNames[k];
			var currentFileNameId 	= 	tempFileNameObject.id;
			var fileNameTot = document.getElementById(currentFileNameId).value
			if (fileNameTot.length != 0) {fileNameVal  += 	fileNameTot + "&";}		
		}
		//将所有的filename的值以&连接传入fileName_total
		document.getElementById("fileName_total").value = fileNameVal;
	}

	function init_data(data){
		$('#projectChief').val(data.projectChief);//项目总监
		$('#projectManager').val(data.projectManager);//项目总监

		//文件部分填写已上传文件名
		//与委托信息那里一样，等那里改好了就可以了
		//任务是将返回的文件名填入到已上传文件名那里
	}

	function init_file(data){
		var list = data.tFileForm;
		    
		$('.origin').each(function(index,element){
			if (list[index].fileFormFilename == null) {
		    	$(this).text("未上传");
		    }
		    else{
		    	$(this).text(list[index].fileFormFilename)
		    	//填写审核状态，只有在原始文件名非空的情况下才有状态
		    	var status = list[index].fileFormCurrentStatus;
		    	if(status == null)
		    		status = "";
		    	else if(status == "D")
		    		status = "已上传";
		    	else if(status == "W")
		    		status = "待审核";
		    	else if(status == "N")
		    		status = "审核未通过";
		    	else if(status == "P")
		    		status = "审核通过";
		    	$(this).parent().next().children().text(status);
		    }
		});
		
	}
	
	</script>
</head>

<body>
    <br/>
	<span>子项目名称：</span><span id="projectName"></span>
	<br/>

<form id="new_form_people" method="post">
 	<!-- <input type="hidden" name="projectId"   		id="projectId" 	value="" />  -->
	<table class="table_new" id="projectMemberTab">
		<tr>
			<td class="td_new_subtitle" colspan="4" ><strong>项目策划——人员派遣信息</strong></td>
		</tr>
	    <tr>
			<td class="td_new_value">项目总监&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td class="td_new_value">
				<input readonly="true" class="easyui-validatebox input_140" type="text"  data-options="validType:'length[2,50]'" id="projectChief" name="projectChief_peoName" />
				<input type="hidden" name="projectChief_peoId"  id="personId" 	value="" />
				<a href="javascript:void(0)"  class="easyui-linkbutton" icon="icon-menu-ADD_ROLE" id="tipProjectPeople1"></a>
			</td>
		</tr>
		 <tr>
			<td class="td_new_name_1">项目经理&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td class="td_new_value">
				<input readonly="true" class="easyui-validatebox input_140" type="text"  data-options="validType:'length[2,50]'" id="projectManager" name="projectManager_peoName" />
				<input type="hidden" name="projectManager_peoId"  id="personId" 	value="" />
				<a href="javascript:void(0)"  class="easyui-linkbutton" icon="icon-menu-ADD_ROLE" id="tipProjectPeople2"></a>
			</td>
		</tr> 
	</table>
	<table class="table_new" >
		<tr>
			<td align="center" width="100%"><a id="btn_submit1" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok">确认提交</a></td>
		</tr>
	</table>
</form>	

<br/>
	

<form id="new_form_file" method="post" enctype="multipart/form-data">
	<input type="hidden" name="projectId"   		id="projectId" 	value="" />
	<!-- <input  name="projectId"   	type="text" 	id="projectId" 	value="" /> -->
	<input type="hidden" name="fileNameTotal" 	id="fileName_total" value="" />
	<table class="table_new" id="fileInfoTab">
		<tr>
			<td class="td_new_subtitle" colspan="4" ><strong>项目策划——表单上传</strong></td>
		</tr>
		<tr>
			<td align="center" width="60px"><strong>名称</strong></td>
			<td align="center" width="60px"><strong>上传</strong></td>
			<td align="center" width="150px"><strong>已上传文件名</strong></td>
			<td align="center" width="80px"><strong>审核状态</strong></td>
		</tr>
		<tr>
			<td><input type="text" 	id="fileName1" 		name="fileName" 	value="总监授权书" 	size="50" readonly/></td>
			<td><input type="file" 	id="fileUpload1" 	name="fileUpload1" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
			<td align="center" ><span class="check"></span></td>
		</tr>
		<tr>
			<td><input type="text" 	id="fileName2" 		name="fileName" 	value="助理授权书" 	size="50" readonly/></td>
			<td><input type="file" 	id="fileUpload2" 	name="fileUpload2" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
			<td align="center" ><span class="check"></span></td>
		</tr>
		<tr>
			<td><input type="text" 	id="fileName3" 		name="fileName" 	value="项目经理任命书" size="50" readonly/></td>
			<td><input type="file" 	id="fileUpload3" 	name="fileUpload3" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
			<td align="center" ><span class="check"></span></td>
		</tr>
		<tr>
			<td><input type="text"  id="fileName4"	 	name="fileName" 	value="监造服务策划表" 		size="50" 	readonly/></td>
			<td><input type="file"  id="fileUpload4" 	name="fileUpload4" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
			<td align="center" ><span class="check"></span></td>
		</tr>
		<tr>
			<td><input type="text" 	id="fileName5" 		name="fileName" 	value="质量计划审批表" 		size="50" 	readonly/></td>
			<td><input type="file" 	id="fileUpload5" 	name="fileUpload5" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
			<td align="center" ><span class="check"></span></td>
		</tr>
		<tr>
			<td><input type="text" 	id="fileName6" 		name="fileName" 	value="编制质量计划" 		size="50" 	readonly/><div><font color="#666">命名方式：业主单位名称+项目名称+监理质量计划</br>编号方式：QR(JS)-Z001(有小到大依次分配)-2016(年份)</font></div></td>
			<td><input type="file" 	id="fileUpload6" 	name="fileUpload6" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
			<td align="center" ><span class="check"></span></td>
		</tr>
			<tr>
			<td><input type="text" 	id="fileName7" 		name="fileName" 	value="验收方案" 		size="50" 	readonly/><div><font color="#666">命名方式：业主单位名称+项目名称+监理质量计划</br>编号方式：QR(JS)-Z001(有小到大依次分配)-2016(年份)</font></div></td>
			<td><input type="file" 	id="fileUpload7" 	name="fileUpload7" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
			<td align="center" ><span class="check"></span></td>
		</tr>
			<tr>
			<td><input type="text" 	id="fileName8" 		name="fileName" 	value="监理细则" 		size="50" 	readonly/><div><font color="#666">命名方式：业主单位名称+项目名称+监理物资名称+驻+生产厂家名称+监理细则。</br>编号方式：2016(年份)-Z001(有小到大依次分配)</font></div></td>
			<td><input type="file" 	id="fileUpload8" 	name="fileUpload8" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
			<td align="center" ><span class="check"></span></td>
		</tr>
	</table>
	</br>
	<table class="table_new">
		<tr>
			<td align="center" width="100%"><a id="btn_submit" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok">确认提交</a></td>
		</tr>
	</table>
	
</form>


<div id="dialog"  style="width:500px;height:280px;padding:10px 20px">
	<table class="table_view2" id="newPeople">
		<tr>
			<td align="center" width="50px">序号</td>
			<td align="center" width="70px">姓名</td>
			<td align="center" width="100px">岗位状态</td>
			<td align="center" width="150px">所在项目</td>
			<td align="center" width="100px">联系电话</td>
			<td align="center" width="100px">休假出差</td>
		</tr>
	</table>
</div>

</body> 
</html>